package com.xinqi.service.impl;

import com.xinqi.service.DynamicTpPoolService;
import com.xinqi.util.pool.TomcatPoolUtil;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.dromara.dynamictp.core.DtpRegistry;
import org.dromara.dynamictp.core.thread.DtpExecutor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.Executor;


/**
 * @author xin麒
 * @date 2023/8/14 0:42
 */
@Slf4j
@Service
public class DynamicTpPoolServiceImpl implements DynamicTpPoolService {

////    @Resource
////    private ThreadPoolTaskExecutor xExecutor;
//
//    @Override
//    public Object processForCountByDynamicTpPoolInNacos(Long count) {
//        tomcatPool.execute(()->{
//            try {
//                Thread.sleep(1000 * 10);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            log.debug("this is execute in pool");
//        });
//
//        log.debug("this is a log1");
//        return "nice nacos!";
//    }
//
//    @Resource
//    private ThreadPoolExecutor tomcatPool;

//    @Autowired
//    private TomcatPoolUtil tomcatPoolUtil;
    @Override
    public Object processForCountByDynamicTpPoolInNacos(Long count) {
//        QueueTypeEnum
        DtpExecutor tomcatTp = DtpRegistry.getDtpExecutor("tomcatTp");
//        Executor executor = tomcatPoolUtil.doGetTp(tomcatTp.);
        tomcatTp.execute(() -> {
            try {
                //
                Thread.sleep(1000 * 10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("this is execute in pool");
        });

        log.debug("this is a log1");
        return "nice nacos!";
    }
}
